<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>S110_nRF51822/Source/ble/ble_services/ble_hrs.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css" />
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="alias.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="alias.js"></script>

<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>


<script type="text/javascript">
  jQuery(document).ready(function () {
    if(gref){ // Number all _img and _table classes
      gref();
    }
  });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->

<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">nRF51822 BLE SDK
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('ble__hrs_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">S110_nRF51822/Source/ble/ble_services/ble_hrs.c</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.</span>
<a name="l00002"></a>00002 <span class="comment"> *</span>
<a name="l00003"></a>00003 <span class="comment"> * The information contained herein is property of Nordic Semiconductor ASA.</span>
<a name="l00004"></a>00004 <span class="comment"> * Terms and conditions of usage are described in detail in NORDIC</span>
<a name="l00005"></a>00005 <span class="comment"> * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.</span>
<a name="l00006"></a>00006 <span class="comment"> *</span>
<a name="l00007"></a>00007 <span class="comment"> * Licensees are granted free, non-transferable use of the information. NO</span>
<a name="l00008"></a>00008 <span class="comment"> * WARRANTY of ANY KIND is provided. This heading must NOT be removed from</span>
<a name="l00009"></a>00009 <span class="comment"> * the file.</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> * $LastChangedRevision$</span>
<a name="l00012"></a>00012 <span class="comment"> */</span>
<a name="l00013"></a>00013 
<a name="l00014"></a>00014 <span class="preprocessor">#include &quot;<a class="code" href="ble__hrs_8h.html">ble_hrs.h</a>&quot;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &quot;<a class="code" href="nordic__common_8h.html" title="Common defines and macros for firmware developed by Nordic Semiconductor.">nordic_common.h</a>&quot;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &quot;ble_l2cap.h&quot;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &quot;<a class="code" href="ble__srv__common_8h.html">ble_srv_common.h</a>&quot;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &quot;<a class="code" href="ble__sdk__util_8h.html">ble_sdk_util.h</a>&quot;</span>
<a name="l00020"></a>00020 
<a name="l00021"></a>00021 
<a name="l00022"></a>00022 <span class="preprocessor">#define OPCODE_LENGTH  1                                                    </span>
<a name="l00023"></a>00023 <span class="preprocessor">#define HANDLE_LENGTH  2                                                    </span>
<a name="l00024"></a>00024 <span class="preprocessor">#define MAX_HRM_LEN    (BLE_L2CAP_MTU_DEF - OPCODE_LENGTH - HANDLE_LENGTH)  </span>
<a name="l00026"></a>00026 <span class="preprocessor">#define INITIAL_VALUE_HRM                       0                           </span>
<a name="l00028"></a>00028 <span class="preprocessor">// Heart Rate Measurement flag bits</span>
<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define HRM_FLAG_MASK_HR_VALUE_16BIT            (0x01 &lt;&lt; 0)                 </span>
<a name="l00030"></a>00030 <span class="preprocessor">#define HRM_FLAG_MASK_SENSOR_CONTACT_DETECTED   (0x01 &lt;&lt; 1)                 </span>
<a name="l00031"></a>00031 <span class="preprocessor">#define HRM_FLAG_MASK_SENSOR_CONTACT_SUPPORTED  (0x01 &lt;&lt; 2)                 </span>
<a name="l00032"></a>00032 <span class="preprocessor">#define HRM_FLAG_MASK_EXPENDED_ENERGY_INCLUDED  (0x01 &lt;&lt; 3)                 </span>
<a name="l00033"></a>00033 <span class="preprocessor">#define HRM_FLAG_MASK_RR_INTERVAL_INCLUDED      (0x01 &lt;&lt; 4)                 </span>
<a name="l00036"></a>00036 <span class="preprocessor">static void on_connect(ble_hrs_t * p_hrs, ble_evt_t * p_ble_evt)</span>
<a name="l00037"></a>00037 <span class="preprocessor"></span>{
<a name="l00038"></a>00038     p_hrs-&gt;conn_handle = p_ble_evt-&gt;evt.gatts_evt.conn_handle;
<a name="l00039"></a>00039 }
<a name="l00040"></a>00040 
<a name="l00041"></a>00041 
<a name="l00042"></a>00042 <span class="keyword">static</span> <span class="keywordtype">void</span> on_disconnect(<a class="code" href="structble__hrs__s.html" title="Heart Rate Service structure. This contains various status information for the service.">ble_hrs_t</a> * p_hrs, <a class="code" href="structble__evt__t.html" title="Common BLE Event type, wrapping the module specific event reports.">ble_evt_t</a> * p_ble_evt)
<a name="l00043"></a>00043 {
<a name="l00044"></a>00044     UNUSED_PARAMETER(p_ble_evt);
<a name="l00045"></a>00045     p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a0d5ffe38d68e48d81e61fc6a4999ae68">conn_handle</a> = <a class="code" href="group___b_l_e___c_o_n_n___h_a_n_d_l_e_s.html#gacf227b9b101dbcf08eccbbaba54e48f5">BLE_CONN_HANDLE_INVALID</a>;
<a name="l00046"></a>00046 }
<a name="l00047"></a>00047 
<a name="l00048"></a>00048 
<a name="l00049"></a>00049 <span class="keyword">static</span> <span class="keywordtype">void</span> on_cccd_write(<a class="code" href="structble__hrs__s.html" title="Heart Rate Service structure. This contains various status information for the service.">ble_hrs_t</a> * p_hrs, <a class="code" href="structble__gatts__evt__write__t.html" title="Event structure for BLE_GATTS_EVT_WRITE.">ble_gatts_evt_write_t</a> * p_evt_write)
<a name="l00050"></a>00050 {
<a name="l00051"></a>00051     <span class="keywordflow">if</span> (p_evt_write-&gt;<a class="code" href="structble__gatts__evt__write__t.html#a8aed22e2c7b283705ec82e0120515618">len</a> == 2)
<a name="l00052"></a>00052     {
<a name="l00053"></a>00053         <span class="comment">// CCCD written, update notification state</span>
<a name="l00054"></a>00054         <span class="keywordflow">if</span> (p_hrs-&gt;<a class="code" href="structble__hrs__s.html#ae1a260338589ff1393ed4e142c3b6114">evt_handler</a> != NULL)
<a name="l00055"></a>00055         {
<a name="l00056"></a>00056             <a class="code" href="structble__hrs__evt__t.html" title="Heart Rate Service event.">ble_hrs_evt_t</a> evt;
<a name="l00057"></a>00057             
<a name="l00058"></a>00058             <span class="keywordflow">if</span> (<a class="code" href="group__ble__sdk__srv__common.html#ga11fd3cc1b15d4bec4accc37618305ccb" title="Inline function for decoding a CCCD value, and then testing if notification is enabled.">ble_srv_is_notification_enabled</a>(p_evt_write-&gt;<a class="code" href="structble__gatts__evt__write__t.html#aa86e1085c6a16f60258f29c9d5fc2144">data</a>))
<a name="l00059"></a>00059             {
<a name="l00060"></a>00060                 evt.<a class="code" href="structble__hrs__evt__t.html#aa8e62db0e9459a38d162f245ea5cc580">evt_type</a> = <a class="code" href="group__ble__sdk__srv__hrs.html#ggaee495052c855cd5345f7301b594763c9a0f13cf6877038b174544d95ee3a40894">BLE_HRS_EVT_NOTIFICATION_ENABLED</a>;
<a name="l00061"></a>00061             }
<a name="l00062"></a>00062             <span class="keywordflow">else</span>
<a name="l00063"></a>00063             {
<a name="l00064"></a>00064                 evt.<a class="code" href="structble__hrs__evt__t.html#aa8e62db0e9459a38d162f245ea5cc580">evt_type</a> = <a class="code" href="group__ble__sdk__srv__hrs.html#ggaee495052c855cd5345f7301b594763c9a1ed0b327eecae450aa039af15ddae345">BLE_HRS_EVT_NOTIFICATION_DISABLED</a>;
<a name="l00065"></a>00065             }
<a name="l00066"></a>00066             
<a name="l00067"></a>00067             p_hrs-&gt;<a class="code" href="structble__hrs__s.html#ae1a260338589ff1393ed4e142c3b6114">evt_handler</a>(p_hrs, &amp;evt);
<a name="l00068"></a>00068         }
<a name="l00069"></a>00069     }
<a name="l00070"></a>00070 }
<a name="l00071"></a>00071 
<a name="l00072"></a>00072 
<a name="l00073"></a>00073 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__pwr__mgmt__main.html#ga70525a816fec301fa4c9d564831c440b" title="Funtion that evaluates the value written in CCCD.">on_write</a>(<a class="code" href="structble__hrs__s.html" title="Heart Rate Service structure. This contains various status information for the service.">ble_hrs_t</a> * p_hrs, <a class="code" href="structble__evt__t.html" title="Common BLE Event type, wrapping the module specific event reports.">ble_evt_t</a> * p_ble_evt)
<a name="l00074"></a>00074 {
<a name="l00075"></a>00075     <a class="code" href="structble__gatts__evt__write__t.html" title="Event structure for BLE_GATTS_EVT_WRITE.">ble_gatts_evt_write_t</a> * p_evt_write = &amp;p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a91857ca158f0c4e43f610068772c7d3d">gatts_evt</a>.params.<a class="code" href="structble__gatts__evt__t.html#a682c515271ef8a1b93b7643a1023e8b8">write</a>;
<a name="l00076"></a>00076     
<a name="l00077"></a>00077     <span class="keywordflow">if</span> (p_evt_write-&gt;<a class="code" href="structble__gatts__evt__write__t.html#af242d6e3b6108ea75e1eb236e94c8240">handle</a> == p_hrs-&gt;<a class="code" href="structble__hrs__s.html#af683c5e3e8c692ba6c20d8941483ce50">hrm_handles</a>.<a class="code" href="structble__gatts__char__handles__t.html#a2c7796d4eb58c25a1a724bcd9d5bf183">cccd_handle</a>)
<a name="l00078"></a>00078     {
<a name="l00079"></a>00079         on_cccd_write(p_hrs, p_evt_write);
<a name="l00080"></a>00080     }
<a name="l00081"></a>00081 }
<a name="l00082"></a>00082 
<a name="l00083"></a>00083 
<a name="l00084"></a><a class="code" href="group__ble__sdk__srv__hrs.html#gac50e029608199cc8d52463acb3e8a02e">00084</a> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__srv__hrs.html#gac50e029608199cc8d52463acb3e8a02e" title="Heart Rate Service BLE stack event handler.">ble_hrs_on_ble_evt</a>(<a class="code" href="structble__hrs__s.html" title="Heart Rate Service structure. This contains various status information for the service.">ble_hrs_t</a> * p_hrs, <a class="code" href="structble__evt__t.html" title="Common BLE Event type, wrapping the module specific event reports.">ble_evt_t</a> * p_ble_evt)
<a name="l00085"></a>00085 {
<a name="l00086"></a>00086     <span class="keywordflow">switch</span> (p_ble_evt-&gt;<a class="code" href="structble__evt__t.html#a50f33abba5627a26728ba30fffd9880a">header</a>.<a class="code" href="structble__evt__hdr__t.html#a826314e7ea25d4267621899efe6859f9">evt_id</a>)
<a name="l00087"></a>00087     {
<a name="l00088"></a>00088         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035daa0b4789724d202a13a5e7eab85c52957">BLE_GAP_EVT_CONNECTED</a>:
<a name="l00089"></a>00089             on_connect(p_hrs, p_ble_evt);
<a name="l00090"></a>00090             <span class="keywordflow">break</span>;
<a name="l00091"></a>00091             
<a name="l00092"></a>00092         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da057001bbd6ea9e615f19ef93cc0831ee">BLE_GAP_EVT_DISCONNECTED</a>:
<a name="l00093"></a>00093             on_disconnect(p_hrs, p_ble_evt);
<a name="l00094"></a>00094             <span class="keywordflow">break</span>;
<a name="l00095"></a>00095             
<a name="l00096"></a>00096         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_t_t_s.html#gga80155586fa275b28773c9b203f52cabaaa68b7764f5264ff092d2ad17851355ed">BLE_GATTS_EVT_WRITE</a>:
<a name="l00097"></a>00097             <a class="code" href="group__ble__sdk__app__pwr__mgmt__main.html#ga70525a816fec301fa4c9d564831c440b" title="Funtion that evaluates the value written in CCCD.">on_write</a>(p_hrs, p_ble_evt);
<a name="l00098"></a>00098             <span class="keywordflow">break</span>;
<a name="l00099"></a>00099             
<a name="l00100"></a>00100         <span class="keywordflow">default</span>:
<a name="l00101"></a>00101             <span class="keywordflow">break</span>;
<a name="l00102"></a>00102     }
<a name="l00103"></a>00103 }
<a name="l00104"></a>00104 
<a name="l00105"></a>00105 
<a name="l00106"></a>00106 <span class="keyword">static</span> uint8_t hrm_encode(<a class="code" href="structble__hrs__s.html" title="Heart Rate Service structure. This contains various status information for the service.">ble_hrs_t</a> * p_hrs, uint16_t heart_rate, uint8_t * p_encoded_buffer)
<a name="l00107"></a>00107 {
<a name="l00108"></a>00108     uint8_t flags = 0;
<a name="l00109"></a>00109     uint8_t len   = 1;
<a name="l00110"></a>00110     <span class="keywordtype">int</span>     i;
<a name="l00111"></a>00111     
<a name="l00112"></a>00112     <span class="comment">// Set sensor contact related flags</span>
<a name="l00113"></a>00113     <span class="keywordflow">if</span> (p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a72fb2dea328affc259a55ca2447d0a48">is_sensor_contact_supported</a>)
<a name="l00114"></a>00114     {
<a name="l00115"></a>00115         flags |= HRM_FLAG_MASK_SENSOR_CONTACT_SUPPORTED;
<a name="l00116"></a>00116     }
<a name="l00117"></a>00117     <span class="keywordflow">if</span> (p_hrs-&gt;<a class="code" href="structble__hrs__s.html#ab02281a680ac723b2a531198b6b0cacc">is_sensor_contact_detected</a>)
<a name="l00118"></a>00118     {
<a name="l00119"></a>00119         flags |= HRM_FLAG_MASK_SENSOR_CONTACT_DETECTED;
<a name="l00120"></a>00120     }
<a name="l00121"></a>00121 
<a name="l00122"></a>00122     <span class="comment">// Encode heart rate measurement</span>
<a name="l00123"></a>00123     <span class="keywordflow">if</span> (heart_rate &gt; 0xff)
<a name="l00124"></a>00124     {
<a name="l00125"></a>00125         flags |= HRM_FLAG_MASK_HR_VALUE_16BIT;
<a name="l00126"></a>00126         len += <a class="code" href="group__ble__sdk__lib__util.html#gab58c28346b89382397aa7a716bf9a178" title="Inline function for encoding a uint16 value.">uint16_encode</a>(heart_rate, &amp;p_encoded_buffer[len]);
<a name="l00127"></a>00127     }
<a name="l00128"></a>00128     <span class="keywordflow">else</span>
<a name="l00129"></a>00129     {
<a name="l00130"></a>00130         p_encoded_buffer[len++] = (uint8_t)heart_rate;
<a name="l00131"></a>00131     }
<a name="l00132"></a>00132     
<a name="l00133"></a>00133     <span class="comment">// Encode rr_interval values</span>
<a name="l00134"></a>00134     <span class="keywordflow">if</span> (p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a857463b940e3e01fdc2ed562b8e69d11">rr_interval_count</a> &gt; 0)
<a name="l00135"></a>00135     {
<a name="l00136"></a>00136         flags |= HRM_FLAG_MASK_RR_INTERVAL_INCLUDED;
<a name="l00137"></a>00137     }
<a name="l00138"></a>00138     <span class="keywordflow">for</span> (i = 0; i &lt; p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a857463b940e3e01fdc2ed562b8e69d11">rr_interval_count</a>; i++)
<a name="l00139"></a>00139     {
<a name="l00140"></a>00140         <span class="keywordflow">if</span> (len + <span class="keyword">sizeof</span>(uint16_t) &gt; MAX_HRM_LEN)
<a name="l00141"></a>00141         {
<a name="l00142"></a>00142             <span class="comment">// Not all stored rr_interval values can fit into the encoded hrm,</span>
<a name="l00143"></a>00143             <span class="comment">// move the remaining values to the start of the buffer.</span>
<a name="l00144"></a>00144             memmove(&amp;p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a49ef1da8cb2099d18429a7483388fbc3">rr_interval</a>[0],
<a name="l00145"></a>00145                     &amp;p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a49ef1da8cb2099d18429a7483388fbc3">rr_interval</a>[i],
<a name="l00146"></a>00146                     (p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a857463b940e3e01fdc2ed562b8e69d11">rr_interval_count</a> - i) * <span class="keyword">sizeof</span>(uint16_t));
<a name="l00147"></a>00147             <span class="keywordflow">break</span>;
<a name="l00148"></a>00148         }
<a name="l00149"></a>00149         len += <a class="code" href="group__ble__sdk__lib__util.html#gab58c28346b89382397aa7a716bf9a178" title="Inline function for encoding a uint16 value.">uint16_encode</a>(p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a49ef1da8cb2099d18429a7483388fbc3">rr_interval</a>[i], &amp;p_encoded_buffer[len]);
<a name="l00150"></a>00150     }
<a name="l00151"></a>00151     p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a857463b940e3e01fdc2ed562b8e69d11">rr_interval_count</a> -= i;
<a name="l00152"></a>00152 
<a name="l00153"></a>00153     <span class="comment">// Add flags</span>
<a name="l00154"></a>00154     p_encoded_buffer[0] = flags;
<a name="l00155"></a>00155     
<a name="l00156"></a>00156     <span class="keywordflow">return</span> len;
<a name="l00157"></a>00157 }
<a name="l00158"></a>00158 
<a name="l00159"></a>00159 
<a name="l00160"></a>00160 <span class="keyword">static</span> uint32_t heart_rate_measurement_char_add(<a class="code" href="structble__hrs__s.html" title="Heart Rate Service structure. This contains various status information for the service.">ble_hrs_t</a> *            p_hrs,
<a name="l00161"></a>00161                                                 <span class="keyword">const</span> <a class="code" href="structble__hrs__init__t.html" title="Heart Rate Service init structure. This contains all options and data needed for initialization of th...">ble_hrs_init_t</a> * p_hrs_init)
<a name="l00162"></a>00162 {
<a name="l00163"></a>00163     <a class="code" href="structble__gatts__char__md__t.html" title="GATT Characteristic Medatadata.">ble_gatts_char_md_t</a> char_md;
<a name="l00164"></a>00164     <a class="code" href="structble__gatts__attr__md__t.html" title="Attribute metadata.">ble_gatts_attr_md_t</a> cccd_md;
<a name="l00165"></a>00165     <a class="code" href="structble__gatts__attr__t.html" title="GATT Attribute.">ble_gatts_attr_t</a>    attr_char_value;
<a name="l00166"></a>00166     <a class="code" href="structble__uuid__t.html" title="Bluetooth Low Energy UUID type, encapsulates both 16-bit and 128-bit UUIDs.">ble_uuid_t</a>          ble_uuid;
<a name="l00167"></a>00167     <a class="code" href="structble__gatts__attr__md__t.html" title="Attribute metadata.">ble_gatts_attr_md_t</a> attr_md;
<a name="l00168"></a>00168     uint8_t             encoded_initial_hrm[MAX_HRM_LEN];
<a name="l00169"></a>00169     
<a name="l00170"></a>00170     memset(&amp;cccd_md, 0, <span class="keyword">sizeof</span>(cccd_md));
<a name="l00171"></a>00171 
<a name="l00172"></a>00172     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;cccd_md.<a class="code" href="structble__gatts__attr__md__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00173"></a>00173     cccd_md.<a class="code" href="structble__gatts__attr__md__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a> = p_hrs_init-&gt;<a class="code" href="structble__hrs__init__t.html#a670a4c608f847ac03bd66005b30068c3">hrs_hrm_attr_md</a>.cccd_write_perm;
<a name="l00174"></a>00174 
<a name="l00175"></a>00175     memset(&amp;char_md, 0, <span class="keyword">sizeof</span>(char_md));
<a name="l00176"></a>00176     
<a name="l00177"></a>00177     char_md.<a class="code" href="structble__gatts__char__md__t.html#a5d81476b727bf4053879046f72049b48">char_properties</a>.<a class="code" href="structble__gatts__char__properties__t.html#ab4ddab4f7ba8461e378ffa590bb15dd8">notify</a> = 1;
<a name="l00178"></a>00178     char_md.<a class="code" href="structble__gatts__char__md__t.html#a48ddd998bdda2b2b93e305ba46137d41">p_char_user_desc</a>       = NULL;
<a name="l00179"></a>00179     char_md.<a class="code" href="structble__gatts__char__md__t.html#ad1fe5fdc8f07028e11054f2288c7fc14">p_char_pf</a>              = NULL;
<a name="l00180"></a>00180     char_md.<a class="code" href="structble__gatts__char__md__t.html#a2bce0c863bf96476ad1629c676042d34">p_user_desc_md</a>         = NULL;
<a name="l00181"></a>00181     char_md.<a class="code" href="structble__gatts__char__md__t.html#a5d654340f27d7c8f113a45beebb50312">p_cccd_md</a>              = &amp;cccd_md;
<a name="l00182"></a>00182     char_md.<a class="code" href="structble__gatts__char__md__t.html#a642bc361c2131bdf054da18ce4e9a3e7">p_sccd_md</a>              = NULL;
<a name="l00183"></a>00183     
<a name="l00184"></a>00184     <a class="code" href="group__ble__types.html#gac4478362651889d2ade8030f53713588" title="Set .type and .uuid fields of ble_uuid_struct to specified uuid value.">BLE_UUID_BLE_ASSIGN</a>(ble_uuid, <a class="code" href="group___u_u_i_d___c_h_a_r_a_c_t_e_r_i_s_t_i_c_s.html#ga2aa05a5800902525167c99d2a9dbe24b">BLE_UUID_HEART_RATE_MEASUREMENT_CHAR</a>);
<a name="l00185"></a>00185     
<a name="l00186"></a>00186     memset(&amp;attr_md, 0, <span class="keyword">sizeof</span>(attr_md));
<a name="l00187"></a>00187 
<a name="l00188"></a>00188     attr_md.<a class="code" href="structble__gatts__attr__md__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>  = p_hrs_init-&gt;<a class="code" href="structble__hrs__init__t.html#a670a4c608f847ac03bd66005b30068c3">hrs_hrm_attr_md</a>.<a class="code" href="structble__srv__cccd__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>;
<a name="l00189"></a>00189     attr_md.<a class="code" href="structble__gatts__attr__md__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a> = p_hrs_init-&gt;<a class="code" href="structble__hrs__init__t.html#a670a4c608f847ac03bd66005b30068c3">hrs_hrm_attr_md</a>.<a class="code" href="structble__srv__cccd__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>;
<a name="l00190"></a>00190     attr_md.<a class="code" href="structble__gatts__attr__md__t.html#ac68fa2d9eb5f49771a80414d2c6bb690">rd_defer</a>   = 0;
<a name="l00191"></a>00191     attr_md.<a class="code" href="structble__gatts__attr__md__t.html#ad44d77b2d08d2dde61c9ccbb22fa7432">wr_defer</a>   = 0;
<a name="l00192"></a>00192     attr_md.<a class="code" href="structble__gatts__attr__md__t.html#a248864ad6fe6949aa81d376cdd7d07b4">vlen</a>       = 1;
<a name="l00193"></a>00193     
<a name="l00194"></a>00194     memset(&amp;attr_char_value, 0, <span class="keyword">sizeof</span>(attr_char_value));
<a name="l00195"></a>00195     
<a name="l00196"></a>00196     attr_char_value.<a class="code" href="structble__gatts__attr__t.html#a8af1eafb75d1d1e9c4cacf188fad299e">p_uuid</a>       = &amp;ble_uuid;
<a name="l00197"></a>00197     attr_char_value.<a class="code" href="structble__gatts__attr__t.html#a573caddb6f66206646fcf38fa7c1a211">p_attr_md</a>    = &amp;attr_md;
<a name="l00198"></a>00198     attr_char_value.<a class="code" href="structble__gatts__attr__t.html#a9e68f6d248f0c128406979df16f88255">init_len</a>     = hrm_encode(p_hrs, INITIAL_VALUE_HRM, encoded_initial_hrm);
<a name="l00199"></a>00199     attr_char_value.<a class="code" href="structble__gatts__attr__t.html#a44cd93c5a44c06d426920c36a3971eb1">init_offs</a>    = 0;
<a name="l00200"></a>00200     attr_char_value.<a class="code" href="structble__gatts__attr__t.html#a1a6c02276292f164788906e8d5a316e5">max_len</a>      = MAX_HRM_LEN;
<a name="l00201"></a>00201     attr_char_value.<a class="code" href="structble__gatts__attr__t.html#ac439d398694461e592c0af528994705e">p_init_value</a> = encoded_initial_hrm;
<a name="l00202"></a>00202     
<a name="l00203"></a>00203     <span class="keywordflow">return</span> <a class="code" href="group___b_l_e___g_a_t_t_s.html#gae4a1d9149f4531d66d06bf289886106d" title="Add a characteristic declaration, a characteristic value declaration and optional characteristic desc...">ble_gatts_characteristic_add</a>(p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a363e00d9262febd8d752ed2f933be1e4">service_handle</a>,
<a name="l00204"></a>00204                                         &amp;char_md,
<a name="l00205"></a>00205                                         &amp;attr_char_value,
<a name="l00206"></a>00206                                         &amp;p_hrs-&gt;<a class="code" href="structble__hrs__s.html#af683c5e3e8c692ba6c20d8941483ce50">hrm_handles</a>);
<a name="l00207"></a>00207 }
<a name="l00208"></a>00208 
<a name="l00209"></a>00209 
<a name="l00210"></a>00210 <span class="keyword">static</span> uint32_t body_sensor_location_char_add(<a class="code" href="structble__hrs__s.html" title="Heart Rate Service structure. This contains various status information for the service.">ble_hrs_t</a> * p_hrs, <span class="keyword">const</span> <a class="code" href="structble__hrs__init__t.html" title="Heart Rate Service init structure. This contains all options and data needed for initialization of th...">ble_hrs_init_t</a> * p_hrs_init)
<a name="l00211"></a>00211 {
<a name="l00212"></a>00212     <a class="code" href="structble__gatts__char__md__t.html" title="GATT Characteristic Medatadata.">ble_gatts_char_md_t</a> char_md;
<a name="l00213"></a>00213     <a class="code" href="structble__gatts__attr__t.html" title="GATT Attribute.">ble_gatts_attr_t</a>    attr_char_value;
<a name="l00214"></a>00214     <a class="code" href="structble__uuid__t.html" title="Bluetooth Low Energy UUID type, encapsulates both 16-bit and 128-bit UUIDs.">ble_uuid_t</a>          ble_uuid;
<a name="l00215"></a>00215     <a class="code" href="structble__gatts__attr__md__t.html" title="Attribute metadata.">ble_gatts_attr_md_t</a> attr_md;
<a name="l00216"></a>00216     
<a name="l00217"></a>00217     memset(&amp;char_md, 0, <span class="keyword">sizeof</span>(char_md));
<a name="l00218"></a>00218     
<a name="l00219"></a>00219     char_md.<a class="code" href="structble__gatts__char__md__t.html#a5d81476b727bf4053879046f72049b48">char_properties</a>.<a class="code" href="structble__gatts__char__properties__t.html#ad99a3f990d972bf0b87f25fd507eb599">read</a> = 1;
<a name="l00220"></a>00220     char_md.<a class="code" href="structble__gatts__char__md__t.html#a48ddd998bdda2b2b93e305ba46137d41">p_char_user_desc</a>     = NULL;
<a name="l00221"></a>00221     char_md.<a class="code" href="structble__gatts__char__md__t.html#ad1fe5fdc8f07028e11054f2288c7fc14">p_char_pf</a>            = NULL;
<a name="l00222"></a>00222     char_md.<a class="code" href="structble__gatts__char__md__t.html#a2bce0c863bf96476ad1629c676042d34">p_user_desc_md</a>       = NULL;
<a name="l00223"></a>00223     char_md.<a class="code" href="structble__gatts__char__md__t.html#a5d654340f27d7c8f113a45beebb50312">p_cccd_md</a>            = NULL;
<a name="l00224"></a>00224     char_md.<a class="code" href="structble__gatts__char__md__t.html#a642bc361c2131bdf054da18ce4e9a3e7">p_sccd_md</a>            = NULL;
<a name="l00225"></a>00225     
<a name="l00226"></a>00226     <a class="code" href="group__ble__types.html#gac4478362651889d2ade8030f53713588" title="Set .type and .uuid fields of ble_uuid_struct to specified uuid value.">BLE_UUID_BLE_ASSIGN</a>(ble_uuid, <a class="code" href="group___u_u_i_d___c_h_a_r_a_c_t_e_r_i_s_t_i_c_s.html#ga6c4ed03e36ad601161835e9f8f5df48e">BLE_UUID_BODY_SENSOR_LOCATION_CHAR</a>);
<a name="l00227"></a>00227     
<a name="l00228"></a>00228     memset(&amp;attr_md, 0, <span class="keyword">sizeof</span>(attr_md));
<a name="l00229"></a>00229 
<a name="l00230"></a>00230     attr_md.<a class="code" href="structble__gatts__attr__md__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>  = p_hrs_init-&gt;<a class="code" href="structble__hrs__init__t.html#a2b688c05a8f04acd31acf2c55c3efc84">hrs_bsl_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>;
<a name="l00231"></a>00231     attr_md.<a class="code" href="structble__gatts__attr__md__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a> = p_hrs_init-&gt;<a class="code" href="structble__hrs__init__t.html#a2b688c05a8f04acd31acf2c55c3efc84">hrs_bsl_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>;
<a name="l00232"></a>00232     attr_md.<a class="code" href="structble__gatts__attr__md__t.html#ac68fa2d9eb5f49771a80414d2c6bb690">rd_defer</a>   = 0;
<a name="l00233"></a>00233     attr_md.<a class="code" href="structble__gatts__attr__md__t.html#ad44d77b2d08d2dde61c9ccbb22fa7432">wr_defer</a>   = 0;
<a name="l00234"></a>00234     attr_md.<a class="code" href="structble__gatts__attr__md__t.html#a248864ad6fe6949aa81d376cdd7d07b4">vlen</a>       = 0;
<a name="l00235"></a>00235     
<a name="l00236"></a>00236     memset(&amp;attr_char_value, 0, <span class="keyword">sizeof</span>(attr_char_value));
<a name="l00237"></a>00237     
<a name="l00238"></a>00238     attr_char_value.<a class="code" href="structble__gatts__attr__t.html#a8af1eafb75d1d1e9c4cacf188fad299e">p_uuid</a>       = &amp;ble_uuid;
<a name="l00239"></a>00239     attr_char_value.<a class="code" href="structble__gatts__attr__t.html#a573caddb6f66206646fcf38fa7c1a211">p_attr_md</a>    = &amp;attr_md;
<a name="l00240"></a>00240     attr_char_value.<a class="code" href="structble__gatts__attr__t.html#a9e68f6d248f0c128406979df16f88255">init_len</a>     = <span class="keyword">sizeof</span>(uint8_t);
<a name="l00241"></a>00241     attr_char_value.<a class="code" href="structble__gatts__attr__t.html#a44cd93c5a44c06d426920c36a3971eb1">init_offs</a>    = 0;
<a name="l00242"></a>00242     attr_char_value.<a class="code" href="structble__gatts__attr__t.html#a1a6c02276292f164788906e8d5a316e5">max_len</a>      = <span class="keyword">sizeof</span>(uint8_t);
<a name="l00243"></a>00243     attr_char_value.<a class="code" href="structble__gatts__attr__t.html#ac439d398694461e592c0af528994705e">p_init_value</a> = p_hrs_init-&gt;<a class="code" href="structble__hrs__init__t.html#a89a0f7e39b46019e49fb392689f6073c">p_body_sensor_location</a>;
<a name="l00244"></a>00244     
<a name="l00245"></a>00245     <span class="keywordflow">return</span> <a class="code" href="group___b_l_e___g_a_t_t_s.html#gae4a1d9149f4531d66d06bf289886106d" title="Add a characteristic declaration, a characteristic value declaration and optional characteristic desc...">ble_gatts_characteristic_add</a>(p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a363e00d9262febd8d752ed2f933be1e4">service_handle</a>,
<a name="l00246"></a>00246                                         &amp;char_md,
<a name="l00247"></a>00247                                         &amp;attr_char_value,
<a name="l00248"></a>00248                                         &amp;p_hrs-&gt;<a class="code" href="structble__hrs__s.html#ac8656c3316e4033d2b5272af9b78234b">bsl_handles</a>);
<a name="l00249"></a>00249 }
<a name="l00250"></a>00250 
<a name="l00251"></a>00251 
<a name="l00252"></a><a class="code" href="group__ble__sdk__srv__hrs.html#ga94256c7eb29129ff352ca53adf1ad5b8">00252</a> uint32_t <a class="code" href="group__ble__sdk__srv__hrs.html#ga94256c7eb29129ff352ca53adf1ad5b8" title="Initialize the Heart Rate Service.">ble_hrs_init</a>(<a class="code" href="structble__hrs__s.html" title="Heart Rate Service structure. This contains various status information for the service.">ble_hrs_t</a> * p_hrs, <span class="keyword">const</span> <a class="code" href="structble__hrs__init__t.html" title="Heart Rate Service init structure. This contains all options and data needed for initialization of th...">ble_hrs_init_t</a> * p_hrs_init)
<a name="l00253"></a>00253 {
<a name="l00254"></a>00254     uint32_t   err_code;
<a name="l00255"></a>00255     <a class="code" href="structble__uuid__t.html" title="Bluetooth Low Energy UUID type, encapsulates both 16-bit and 128-bit UUIDs.">ble_uuid_t</a> ble_uuid;
<a name="l00256"></a>00256 
<a name="l00257"></a>00257     <span class="comment">// Initialize service structure</span>
<a name="l00258"></a>00258     p_hrs-&gt;<a class="code" href="structble__hrs__s.html#ae1a260338589ff1393ed4e142c3b6114">evt_handler</a>                 = p_hrs_init-&gt;<a class="code" href="structble__hrs__init__t.html#ae1a260338589ff1393ed4e142c3b6114">evt_handler</a>;
<a name="l00259"></a>00259     p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a72fb2dea328affc259a55ca2447d0a48">is_sensor_contact_supported</a> = p_hrs_init-&gt;<a class="code" href="structble__hrs__init__t.html#a72fb2dea328affc259a55ca2447d0a48">is_sensor_contact_supported</a>;
<a name="l00260"></a>00260     p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a0d5ffe38d68e48d81e61fc6a4999ae68">conn_handle</a>                 = <a class="code" href="group___b_l_e___c_o_n_n___h_a_n_d_l_e_s.html#gacf227b9b101dbcf08eccbbaba54e48f5">BLE_CONN_HANDLE_INVALID</a>;
<a name="l00261"></a>00261     p_hrs-&gt;<a class="code" href="structble__hrs__s.html#ab02281a680ac723b2a531198b6b0cacc">is_sensor_contact_detected</a>  = <span class="keyword">false</span>;
<a name="l00262"></a>00262     p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a857463b940e3e01fdc2ed562b8e69d11">rr_interval_count</a>           = 0;
<a name="l00263"></a>00263     
<a name="l00264"></a>00264     <span class="comment">// Add service</span>
<a name="l00265"></a>00265     <a class="code" href="group__ble__types.html#gac4478362651889d2ade8030f53713588" title="Set .type and .uuid fields of ble_uuid_struct to specified uuid value.">BLE_UUID_BLE_ASSIGN</a>(ble_uuid, <a class="code" href="group___u_u_i_d___s_e_r_v_i_c_e_s.html#gada8a8d4952d86f3557365ce0ead40e15">BLE_UUID_HEART_RATE_SERVICE</a>);
<a name="l00266"></a>00266 
<a name="l00267"></a>00267     err_code = <a class="code" href="group___b_l_e___g_a_t_t_s.html#ga5e8270fe6dfa01e446be17b48fe81e2a" title="Add a service declaration to the local server database.">ble_gatts_service_add</a>(<a class="code" href="group___b_l_e___g_a_t_t_s___s_v_c___t_y_p_e_s.html#ga713ed30865fa70c89587ba981f114a91">BLE_GATTS_SVC_TYPE_PRIMARY</a>, &amp;ble_uuid, &amp;p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a363e00d9262febd8d752ed2f933be1e4">service_handle</a>);
<a name="l00268"></a>00268     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00269"></a>00269     {
<a name="l00270"></a>00270         <span class="keywordflow">return</span> err_code;
<a name="l00271"></a>00271     }
<a name="l00272"></a>00272     
<a name="l00273"></a>00273     <span class="comment">// Add heart rate measurement characteristic</span>
<a name="l00274"></a>00274     err_code = heart_rate_measurement_char_add(p_hrs, p_hrs_init);
<a name="l00275"></a>00275     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00276"></a>00276     {
<a name="l00277"></a>00277         <span class="keywordflow">return</span> err_code;
<a name="l00278"></a>00278     }
<a name="l00279"></a>00279     
<a name="l00280"></a>00280     <span class="keywordflow">if</span> (p_hrs_init-&gt;<a class="code" href="structble__hrs__init__t.html#a89a0f7e39b46019e49fb392689f6073c">p_body_sensor_location</a> != NULL)
<a name="l00281"></a>00281     {
<a name="l00282"></a>00282         <span class="comment">// Add body sensor location characteristic</span>
<a name="l00283"></a>00283         err_code = body_sensor_location_char_add(p_hrs, p_hrs_init);
<a name="l00284"></a>00284         <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00285"></a>00285         {
<a name="l00286"></a>00286             <span class="keywordflow">return</span> err_code;
<a name="l00287"></a>00287         }
<a name="l00288"></a>00288     }
<a name="l00289"></a>00289     
<a name="l00290"></a>00290     <span class="keywordflow">return</span> <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>;
<a name="l00291"></a>00291 }
<a name="l00292"></a>00292 
<a name="l00293"></a>00293 
<a name="l00294"></a><a class="code" href="group__ble__sdk__srv__hrs.html#gabe5fed48baeb4a518a51bd7e2e5f010e">00294</a> uint32_t <a class="code" href="group__ble__sdk__srv__hrs.html#gabe5fed48baeb4a518a51bd7e2e5f010e" title="Sends heart rate measurement if notification has been enabled.">ble_hrs_heart_rate_measurement_send</a>(<a class="code" href="structble__hrs__s.html" title="Heart Rate Service structure. This contains various status information for the service.">ble_hrs_t</a> * p_hrs, uint16_t heart_rate)
<a name="l00295"></a>00295 {
<a name="l00296"></a>00296     uint32_t err_code;
<a name="l00297"></a>00297     
<a name="l00298"></a>00298     <span class="comment">// Send value if connected and notifying</span>
<a name="l00299"></a>00299     <span class="keywordflow">if</span> (p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a0d5ffe38d68e48d81e61fc6a4999ae68">conn_handle</a> != <a class="code" href="group___b_l_e___c_o_n_n___h_a_n_d_l_e_s.html#gacf227b9b101dbcf08eccbbaba54e48f5">BLE_CONN_HANDLE_INVALID</a>)
<a name="l00300"></a>00300     {
<a name="l00301"></a>00301         uint8_t                encoded_hrm[MAX_HRM_LEN];
<a name="l00302"></a>00302         uint16_t               len;
<a name="l00303"></a>00303         uint16_t               hvx_len;
<a name="l00304"></a>00304         <a class="code" href="structble__gatts__hvx__params__t.html" title="GATT HVx parameters.">ble_gatts_hvx_params_t</a> hvx_params;
<a name="l00305"></a>00305         
<a name="l00306"></a>00306         len     = hrm_encode(p_hrs, heart_rate, encoded_hrm);
<a name="l00307"></a>00307         hvx_len = len;
<a name="l00308"></a>00308 
<a name="l00309"></a>00309         memset(&amp;hvx_params, 0, <span class="keyword">sizeof</span>(hvx_params));
<a name="l00310"></a>00310         
<a name="l00311"></a>00311         hvx_params.<a class="code" href="structble__gatts__hvx__params__t.html#af242d6e3b6108ea75e1eb236e94c8240">handle</a>   = p_hrs-&gt;<a class="code" href="structble__hrs__s.html#af683c5e3e8c692ba6c20d8941483ce50">hrm_handles</a>.<a class="code" href="structble__gatts__char__handles__t.html#a61c5d051b6f79d08236fae6cf7019e75">value_handle</a>;
<a name="l00312"></a>00312         hvx_params.<a class="code" href="structble__gatts__hvx__params__t.html#a470560e997d7a639785b8b405de9df7d">indicate</a> = 0;
<a name="l00313"></a>00313         hvx_params.<a class="code" href="structble__gatts__hvx__params__t.html#ac681806181c80437cfab37335f62ff39">offset</a>   = 0;
<a name="l00314"></a>00314         hvx_params.<a class="code" href="structble__gatts__hvx__params__t.html#a05aad1ca0c545a05986893ca0e1ed34f">p_len</a>    = &amp;hvx_len;
<a name="l00315"></a>00315         hvx_params.<a class="code" href="structble__gatts__hvx__params__t.html#a8304c4af5da6e830b86d7199dc9a22e6">p_data</a>   = encoded_hrm;
<a name="l00316"></a>00316         
<a name="l00317"></a>00317         err_code = <a class="code" href="group___b_l_e___g_a_t_t_s.html#gaab41731020dbcc6b9b561d8129689308" title="Notify or Indicate an attribute value.">ble_gatts_hvx</a>(p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a0d5ffe38d68e48d81e61fc6a4999ae68">conn_handle</a>, &amp;hvx_params);
<a name="l00318"></a>00318         <span class="keywordflow">if</span> ((err_code == <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>) &amp;&amp; (hvx_len != len))
<a name="l00319"></a>00319         {
<a name="l00320"></a>00320             err_code = <a class="code" href="group__nrf__error.html#ga4c61f2b54667506e90cc296721b2e658" title="Data size exceeds limit.">NRF_ERROR_DATA_SIZE</a>;
<a name="l00321"></a>00321         }
<a name="l00322"></a>00322     }
<a name="l00323"></a>00323     <span class="keywordflow">else</span>
<a name="l00324"></a>00324     {
<a name="l00325"></a>00325         err_code = <a class="code" href="group__nrf__error.html#gaf0aff2ba7864b34a36b4a96986e1851e" title="Invalid state, operation disallowed in this state.">NRF_ERROR_INVALID_STATE</a>;
<a name="l00326"></a>00326     }
<a name="l00327"></a>00327 
<a name="l00328"></a>00328     <span class="keywordflow">return</span> err_code;
<a name="l00329"></a>00329 }
<a name="l00330"></a>00330 
<a name="l00331"></a>00331 
<a name="l00332"></a><a class="code" href="group__ble__sdk__srv__hrs.html#gaea316a9c9503571b143d93086295f61a">00332</a> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__srv__hrs.html#gaea316a9c9503571b143d93086295f61a" title="Adds a RR Interval measurement to the RR Interval buffer.">ble_hrs_rr_interval_add</a>(<a class="code" href="structble__hrs__s.html" title="Heart Rate Service structure. This contains various status information for the service.">ble_hrs_t</a> * p_hrs, uint16_t rr_interval)
<a name="l00333"></a>00333 {
<a name="l00334"></a>00334     <span class="keywordflow">if</span> (p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a857463b940e3e01fdc2ed562b8e69d11">rr_interval_count</a> == <a class="code" href="group__ble__sdk__srv__hrs.html#ga2e829f32fd9d57d18d1e8daa7956dee5">BLE_HRS_MAX_BUFFERED_RR_INTERVALS</a>)
<a name="l00335"></a>00335     {
<a name="l00336"></a>00336         <span class="comment">// The rr_interval buffer is full, delete the oldest value</span>
<a name="l00337"></a>00337         memmove(&amp;p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a49ef1da8cb2099d18429a7483388fbc3">rr_interval</a>[0],
<a name="l00338"></a>00338                 &amp;p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a49ef1da8cb2099d18429a7483388fbc3">rr_interval</a>[1],
<a name="l00339"></a>00339                 (<a class="code" href="group__ble__sdk__srv__hrs.html#ga2e829f32fd9d57d18d1e8daa7956dee5">BLE_HRS_MAX_BUFFERED_RR_INTERVALS</a> - 1) * <span class="keyword">sizeof</span>(uint16_t));
<a name="l00340"></a>00340         p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a857463b940e3e01fdc2ed562b8e69d11">rr_interval_count</a>--;
<a name="l00341"></a>00341     }
<a name="l00342"></a>00342     
<a name="l00343"></a>00343     <span class="comment">// Add new value</span>
<a name="l00344"></a>00344     p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a49ef1da8cb2099d18429a7483388fbc3">rr_interval</a>[p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a857463b940e3e01fdc2ed562b8e69d11">rr_interval_count</a>++] = rr_interval;
<a name="l00345"></a>00345 }
<a name="l00346"></a>00346 
<a name="l00347"></a>00347 
<a name="l00348"></a><a class="code" href="group__ble__sdk__srv__hrs.html#gaf207a34d16fbee25b5555fd4192b5b15">00348</a> <span class="keywordtype">bool</span> <a class="code" href="group__ble__sdk__srv__hrs.html#gaf207a34d16fbee25b5555fd4192b5b15" title="Checks if RR Interval buffer is full.">ble_hrs_rr_interval_buffer_is_full</a>(<a class="code" href="structble__hrs__s.html" title="Heart Rate Service structure. This contains various status information for the service.">ble_hrs_t</a> * p_hrs)
<a name="l00349"></a>00349 {
<a name="l00350"></a>00350     <span class="keywordflow">return</span> (p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a857463b940e3e01fdc2ed562b8e69d11">rr_interval_count</a> == <a class="code" href="group__ble__sdk__srv__hrs.html#ga2e829f32fd9d57d18d1e8daa7956dee5">BLE_HRS_MAX_BUFFERED_RR_INTERVALS</a>);
<a name="l00351"></a>00351 }
<a name="l00352"></a>00352 
<a name="l00353"></a>00353 
<a name="l00354"></a><a class="code" href="group__ble__sdk__srv__hrs.html#gad8b66aa54ddf79459271df6ec9b65644">00354</a> uint32_t <a class="code" href="group__ble__sdk__srv__hrs.html#gad8b66aa54ddf79459271df6ec9b65644" title="Sets the state of the Sensor Contact Supported bit.">ble_hrs_sensor_contact_supported_set</a>(<a class="code" href="structble__hrs__s.html" title="Heart Rate Service structure. This contains various status information for the service.">ble_hrs_t</a> * p_hrs, <span class="keywordtype">bool</span> is_sensor_contact_supported)
<a name="l00355"></a>00355 {
<a name="l00356"></a>00356     <span class="comment">// Check if we are connected to peer</span>
<a name="l00357"></a>00357     <span class="keywordflow">if</span> (p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a0d5ffe38d68e48d81e61fc6a4999ae68">conn_handle</a> == <a class="code" href="group___b_l_e___c_o_n_n___h_a_n_d_l_e_s.html#gacf227b9b101dbcf08eccbbaba54e48f5">BLE_CONN_HANDLE_INVALID</a>)
<a name="l00358"></a>00358     {
<a name="l00359"></a>00359         p_hrs-&gt;<a class="code" href="structble__hrs__s.html#a72fb2dea328affc259a55ca2447d0a48">is_sensor_contact_supported</a> = is_sensor_contact_supported;
<a name="l00360"></a>00360         <span class="keywordflow">return</span> <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>;
<a name="l00361"></a>00361     }
<a name="l00362"></a>00362     <span class="keywordflow">else</span>
<a name="l00363"></a>00363     {
<a name="l00364"></a>00364         <span class="keywordflow">return</span> <a class="code" href="group__nrf__error.html#gaf0aff2ba7864b34a36b4a96986e1851e" title="Invalid state, operation disallowed in this state.">NRF_ERROR_INVALID_STATE</a>;
<a name="l00365"></a>00365     }
<a name="l00366"></a>00366 }
<a name="l00367"></a>00367 
<a name="l00368"></a>00368 
<a name="l00369"></a><a class="code" href="group__ble__sdk__srv__hrs.html#ga4eccea2cb1d248ccdc75bebb84c1dff2">00369</a> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__srv__hrs.html#ga4eccea2cb1d248ccdc75bebb84c1dff2" title="Sets the state of the Sensor Contact Detected bit.">ble_hrs_sensor_contact_detected_update</a>(<a class="code" href="structble__hrs__s.html" title="Heart Rate Service structure. This contains various status information for the service.">ble_hrs_t</a> * p_hrs, <span class="keywordtype">bool</span> is_sensor_contact_detected)
<a name="l00370"></a>00370 {
<a name="l00371"></a>00371     p_hrs-&gt;<a class="code" href="structble__hrs__s.html#ab02281a680ac723b2a531198b6b0cacc">is_sensor_contact_detected</a> = is_sensor_contact_detected;
<a name="l00372"></a>00372 }
<a name="l00373"></a>00373 
<a name="l00374"></a>00374 
<a name="l00375"></a><a class="code" href="group__ble__sdk__srv__hrs.html#gab3ec66c7419f5c79ad54f849353e8aea">00375</a> uint32_t <a class="code" href="group__ble__sdk__srv__hrs.html#gab3ec66c7419f5c79ad54f849353e8aea" title="Set the Body Sensor Location.">ble_hrs_body_sensor_location_set</a>(<a class="code" href="structble__hrs__s.html" title="Heart Rate Service structure. This contains various status information for the service.">ble_hrs_t</a> * p_hrs, uint8_t body_sensor_location)
<a name="l00376"></a>00376 {
<a name="l00377"></a>00377     uint16_t len = <span class="keyword">sizeof</span>(uint8_t);
<a name="l00378"></a>00378     <span class="keywordflow">return</span> <a class="code" href="group___b_l_e___g_a_t_t_s.html#ga4267755972361d620ae47d791feec4a5" title="Set the value of a given attribute.">ble_gatts_value_set</a>(p_hrs-&gt;<a class="code" href="structble__hrs__s.html#ac8656c3316e4033d2b5272af9b78234b">bsl_handles</a>.<a class="code" href="structble__gatts__char__handles__t.html#a61c5d051b6f79d08236fae6cf7019e75">value_handle</a>, 0, &amp;len, &amp;body_sensor_location);
<a name="l00379"></a>00379 }
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>ble_hrs.c</b>      </li>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">
      Copyright &copy 2006-2011 <a href="http://www.nordicsemi.no" style="text-decoration:none">Nordic Semiconductor</a>.
      All Rights Reserved.
      <a href="disclaimer.html">Disclaimer</a>
    </li>
   </ul>
 </div>


</body>
</html>
